package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/user/sendMsg")
    public ResultInfo sendSms(@RequestBody Map<String,String> map){
        String phone = map.get("phone");
        userService.sendSms(phone);
        return ResultInfo.success(null);
    }
    @PostMapping("/user/login")
    public ResultInfo login(@RequestBody Map<String,String> map){
        String code = map.get("code");
        String phone = map.get("phone");
        ResultInfo resultInfo=userService.login(code,phone);
        return resultInfo;
    }
    //退出
    //@RequestHeader("key") 可以从请求头中获取任意键的值
    @PostMapping("/user/logout")
    public ResultInfo loginOut(@RequestHeader("Authorization") String token){
        token = token.replace("Bearer", "").trim();
        userService.remove(token);
        return ResultInfo.success(null);
    }


}
